package com.example.mq.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @auth 贾枣阳
 * @date 2021/2/3 10:33
 */
@Component
@RabbitListener(queues = "SECOND_QUEUE")
public class FiveConsumer {
    @RabbitHandler
    public void process(String msg, Message message, Channel channel) throws IOException {

        System.out.println("消费者五收到消息：" + msg);
       /* try {
            *//**
             * 确认一条消息：<br>
             * channel.basicAck(deliveryTag, false); <br>
             * deliveryTag:该消息的index <br>
             * multiple：是否批量.true:将一次性ack所有小于deliveryTag的消息 <br>
             *//*
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            System.out.println("get msg1 success msg = " + msg);

        } catch (Exception e) {
            //消费者处理出了问题，需要告诉队列信息消费失败
            *//**
             * 拒绝确认消息:<br>
             * channel.basicNack(long deliveryTag, boolean multiple, boolean requeue) ; <br>
             * deliveryTag:该消息的index<br>
             * multiple：是否批量.true:将一次性拒绝所有小于deliveryTag的消息。<br>
             * requeue：被拒绝的是否重新入队列 <br>
             *//*
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),
                    false, true);
            System.err.println("get msg1 failed msg = " + msg);

            *//**
             * 拒绝一条消息：<br>
             * channel.basicReject(long deliveryTag, boolean requeue);<br>
             * deliveryTag:该消息的index<br>
             * requeue：被拒绝的是否重新入队列
             *//*
            //channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
        }*/
    }
}
